package jgl.vajra.management.part.login.model;

import java.util.Map;

import io.reactivex.Observable;
import jgl.vajra.management.bean.LoginInfoBean;
import jgl.vajra.management.constant.AppConfig;
import jgl.vajra.management.part.login.contract.LoginContract;
import jgl.vajra.management.utils.RandomUtils;
import jgl.vajra.management.widget.bean.BaseRequestData;
import jgl.vajra.management.widget.manager.RxJavaHttpManager;
import jgl.vajra.management.widget.manager.retrofit.RetrofitJsonManager;
import jgl.vajra.management.widget.retrofithelper.rxschedulers.RxSchedulersHelper;
import jgl.vajra.management.widget.retrofithelper.utils.AEACCoder;

public class LoginModel extends LoginContract.Model{
    @Override
    public Observable<String> getAESSecretKey() {
        return RetrofitJsonManager.getInstance().getApiService().getAESSecretKey(AppConfig.RANDOM_NUMBER)
                .compose(RxJavaHttpManager.applyTransformer());
    }

    @Override
    public Observable<BaseRequestData<String>> getVerifyCode(Map<String, Object> map) {
        return RetrofitJsonManager.getInstance().getApiService().getVerifyCode(map).compose(RxSchedulersHelper.applyIoTransformer());
    }

    @Override
    public Observable<LoginInfoBean> onLogin(Map<String, Object> map) {
        return RetrofitJsonManager.getInstance().getApiService().login(map, AEACCoder.encrypt(RandomUtils.getRandom())).compose(RxJavaHttpManager.applyTransformer());
    }
}
